import BaseController from "../../cfw/mvc/BaseController";
import ModuleManager, { ModuleID } from "../../cfw/module/ModuleManager";
import { UIIndex } from "../../cfw/tools/Define";
import BornController from "../born/BornController";
import ViewManager from "../../engine/ViewManager";
import { ResType } from "../../cfw/res/ResInterface";
import SDKManager from "../../sdk/SDKManager";
import { ResultState, BattleID } from "../../sdk/SDKConfig";
import BagManager from "../bag/BagManager";
import { InitValue } from "../../public/Config";
export default class LoginController extends BaseController {


    private static ins: LoginController;

    static instance() {
        if (!this.ins) {
            this.ins = new LoginController()
        }
        return this.ins;
    }
    intoLayer(prefab: cc.Prefab) {
        ModuleManager.setModuleID(ModuleID.LOGIN)
        ModuleManager.getLoader().cacheRes('prefabs/LoginView', ResType.Prefab, prefab)
        ViewManager.instance().pushPrefab(prefab, 'LoginView', this, null, UIIndex.ROOT)

    }

    intoLobby() {
        SDKManager.getChannel().battleStart(BattleID.LOGIN_TO_LOBBY)
        if (SDKManager.getChannel().isStartErrorClick()) {
            SDKManager.getChannel().showRewardAd(0, (state: ResultState) => {
                if (state) {
                    BagManager.addCoin(InitValue.START_VIDEE_REWARD)
                }
                BornController.instance().intoLayer()
            })
        } else {
            BornController.instance().intoLayer()
        }
       



    }
}
